<template>
    <div style="margin-top:15%; margin-left:40%;">
        <el-form ref="form" :model="form" label-width="80px">
            <el-row>
                <el-col :span="7">
                    <el-form-item label="用户名">
                        <el-input v-model="form.name" type="text">
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="7">
                    <el-form-item label="密码">
                    <el-input v-model="form.password" type="password">
                    </el-input>
                </el-form-item></el-col>
            </el-row>
            <el-row>
                <el-col  :span="2" :offset="3">
                    <el-button type="primary"  style="width:100%" @click="login">登录</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return {form:{
                name:"",
                password:""
                }}
        },
        methods:{
            login:function () {
                this.$http.post("/api/login",this.form).then(result=>{
                    console.log(result);
                    window.localStorage.setItem("token",result);
                    if(result){
                        //this.$message.info("登录成功！");
                        this.$router.push({path:'/list'});
                    }else{
                        this.$message.error("用户名或者密码错误");
                    }
                }).catch(error=>{
                    console.log(error);
                });
            }
        }
    }
</script>

<style scoped>

</style>